home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / freeWAIS-sf-1.1 / ir / udping.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-05  |  2.9 KB  |  106 lines

  1. /* Send an UDP packet containing the program version and UID
  2.    to a compiled-in address */
  3. /* 
  4.      Copyright (c) 1994 Harald T. Alvestrand
  5.  
  6.      The X Consortium, and any party obtaining a copy of these files from
  7.      the X Consortium, directly or indirectly, is granted, free of charge, a
  8.      full and unrestricted irrevocable, world-wide, paid up, royalty-free,
  9.      nonexclusive right and license to deal in this software and
  10.      documentation files (the "Software"), including without limitation the
  11.      rights to use, copy, modify, merge, publish, distribute, sublicense,
  12.      and/or sell copies of the Software, and to permit persons who receive
  13.      copies from any such party to do so.  This license includes without
  14.      limitation a license to do the foregoing actions under any patents of
  15.      the party supplying this software to the X Consortium.
  16.  
  17. */
  18. #include "cdialect.h"
  19. #ifndef DO_NOT_TELL_ABOUT_ME
  20. /*
  21. #include <sys/types.h>
  22. #include <sys/socket.h>
  23. #include <netinet/in.h>
  24. #include <arpa/inet.h>
  25. #include <netdb.h>
  26. #include <stdio.h>
  27. */
  28.  
  29. #include "sockets.h"
  30. #include <sys/utsname.h>
  31.  
  32. #ifndef UDP_PORT_NO
  33. #define UDP_PORT_NO 29659
  34. #endif
  35. #ifndef UDP_HOST_NAME
  36. #define UDP_HOST_NAME "ls6-www.informatik.uni-dortmund.de"
  37. #endif
  38. #ifndef UDP_HOST_NO
  39. #define UDP_HOST_NO "129.217.20.172"
  40. #endif
  41.  
  42. extern uid_t getuid();
  43. extern int socket();
  44. extern int sendto();
  45. extern int close();
  46.  
  47. static int iamhere(progname)
  48.      char *progname;
  49. {
  50.     char buffer[100];
  51.     int s, err;
  52.     struct sockaddr_in to;
  53.     struct protoent *udp;
  54.     struct utsname name;
  55.     struct hostent *host;
  56.  
  57.     /* This routine is made to leave on ANY error AT ALL */
  58.     host = gethostbyname(UDP_HOST_NAME);
  59.     /* Solaris returns > 0, others return = 0 */
  60.     if (uname(&name) < 0) {
  61.        sprintf(buffer, "[%d ???] %.60s", getuid(), progname);
  62.     } else {
  63.        /* Get machine, opsys and release from uname stuff */
  64.        sprintf(buffer, "[uid=%d hw=%.10s os=%.10s osver=%.10s dns=%s cc=%s] %.40s",
  65.             getuid(),
  66.             name.machine, name.sysname, name.release,
  67.             host?"yes":"no",
  68.             COMPILER_VERSION,
  69.             progname);
  70.     }
  71.     udp = getprotobyname("udp");
  72.     if (! udp) return -1;
  73.     s = socket(PF_INET, SOCK_DGRAM, udp->p_proto);
  74.     if (s == -1) return -1;
  75.     to.sin_family = AF_INET;
  76.     to.sin_port = htons(UDP_PORT_NO);
  77.     if (host) {
  78.        to.sin_addr.s_addr = *(u_long*)*(host->h_addr_list);
  79.     } else {
  80. #ifdef __DGUX__
  81.        to.sin_addr = inet_addr(UDP_HOST_NO);
  82. #else
  83.        to.sin_addr.s_addr = inet_addr(UDP_HOST_NO);
  84. #endif
  85.     }
  86.     if (to.sin_addr.s_addr == -1) return -1;
  87.     err = sendto(s, buffer, strlen(buffer), 0, &to, sizeof(to));
  88.     (void) close(s);
  89.     if (err == -1) return -1;
  90.     return 0;
  91. }
  92.  
  93. int sayiamhere()
  94. {
  95.     int stat;
  96.     /* Isolate the call in a new process */
  97.     if (fork() != 0) {
  98.        return 0;
  99.     }
  100.     stat = iamhere(FREE_WAIS_SF_VERSION_STRING);
  101.     exit(stat!=0?1:0);
  102. }
  103.  
  104. #endif
  105. /* DO_NOT_TELL_ABOUT_ME */
  106.